package xyz.scootaloo.oj.offer

import org.junit.Test
import java.util.*

/**
 * @author flutterdash@qq.com
 * @since 2021/4/8 23:01
 */
class P09 {

    inner class CQueue {
        private val stack = Stack<Int>()
        private val tmp = Stack<Int>()

        fun appendTail(value: Int) {
            stack.push(value)
        }

        fun deleteHead(): Int {
            if (stack.isEmpty())
                return -1
            while (!stack.isEmpty()) {
                tmp.push(stack.pop())
            }
            val head = tmp.pop()
            while (!tmp.isEmpty()) {
                stack.push(tmp.pop())
            }
            return head
        }
    }

    @Test
    fun test0() {
        val queue = CQueue()
        queue.appendTail(3)
        println(queue.deleteHead())
        println(queue.deleteHead())
    }

}
